﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OrmAuto;



public partial class Contents_SoluzioniProposte : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        showRicerca(); 

    }//fM

    public void showRicerca()
    {
        if (Request.Form == null) return;
        if (!Request.Form.HasKeys()) return;

        var f = Request.Form;
        var all = f.AllKeys;

        var marca = f[all.Where(k => k.IndexOf("myDropMarche") > 0).FirstOrDefault()];
        var modello = f[all.Where(k => k.IndexOf("myDropModelli") > 0).FirstOrDefault()];
        var possesso = f[all.Where(k => k.IndexOf("myDropPossessi") > 0).FirstOrDefault()];
        var colore = f[all.Where(k => k.IndexOf("myDropColori") > 0).FirstOrDefault()];
        var stati = f[all.Where(k => k.IndexOf("myStatiDrop") > 0).FirstOrDefault()];
        var tipologia = f[all.Where(k => k.IndexOf("myTipiDrop") > 0).FirstOrDefault()];


        var priceStart = f[all.Where(k => k.IndexOf("myPrezzoStartDrop") > 0).FirstOrDefault()];
        var priceFinal = f[all.Where(k => k.IndexOf("myPrezzoFinaleDrop") > 0).FirstOrDefault()];

        var km_Start = f[all.Where(k => k.IndexOf("myKmStartDrop") > 0).FirstOrDefault()];
        var km_Fine = f[all.Where(k => k.IndexOf("myKmFineDrop") > 0).FirstOrDefault()];

        bool ivaDeducibile = false;
        var ivaDed = f[all.Where(k => k.IndexOf("myIvaDedCheck") > 0).FirstOrDefault()];
        if (!string.IsNullOrEmpty(ivaDed))
        {
            if (ivaDed.Equals("on", StringComparison.InvariantCultureIgnoreCase))
                ivaDeducibile = true;
        }

        if (!string.IsNullOrEmpty(priceStart))
            priceStart = priceStart.Replace(".","");
        if (!string.IsNullOrEmpty(priceFinal))
            priceFinal = priceFinal.Replace(".", "");

        if (!string.IsNullOrEmpty(km_Start))
            km_Start = km_Start.Replace(".", "");
        if (!string.IsNullOrEmpty(km_Fine))
            km_Fine = km_Fine.Replace(".", ""); 

        
        int idMarca = 0, idModello = 0, idPossesso = 0, idColore = 0,idTipologia=0,idStato=0;
        int prezzoStart=0,prezzoFinal=0,kmStart=0,kmFine=0;

        int.TryParse(marca, out idMarca);
        int.TryParse(modello, out idModello);
        int.TryParse(possesso, out idPossesso);
        int.TryParse(colore, out idColore);
        int.TryParse(tipologia, out idTipologia);
        int.TryParse(stati, out idStato); 
        int.TryParse(priceStart,out prezzoStart );
        int.TryParse(priceFinal, out prezzoFinal);
        int.TryParse(km_Start, out kmStart);
        int.TryParse(km_Fine, out kmFine);

        if (possesso.Equals("1") )//1 = nuova
        { kmStart = 0; kmFine = 0; }

        DataTable dati = null;

        try
        {
            dati = new OrmAuto.RicercheSql().sp_vAnnVenditaGetBy(
                    idMarca, idModello, idPossesso, idColore,idTipologia,idStato, prezzoStart,prezzoFinal,
                    kmStart,kmFine,ivaDeducibile,true  );
        }
        catch (Exception ex)
        {
            ;
        }

        this.ListView1.DataSource = dati;
        this.ListView1.DataBind();
    }

}
